/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package filmlibrary.web;

import filmlibrary.orm.ORMHelper;
import filmlibrary.orm.classes.Films;
import filmlibrary.orm.classes.Users;
import java.math.BigInteger;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

/**
 *
 * @author karol
 */
public final class Additional {

    // należy zwrócić uwagę na użycie słowa kluczowego volatile
    private static volatile Additional instance = null;

    public static Additional getInstance() {
        if (instance == null) {
            synchronized (Additional.class) {
                if (instance == null) {
                    instance = new Additional();
                }
            }
        }
        return instance;
    }

    // żeby uniknąć automatycznego tworzenia domyślnego, publicznego, bezargumentowego konstruktora
    private Additional() {
    }

    public static String MD5(String message) {

        MessageDigest m = null;
        try {
            m = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Additional.class.getName()).log(Level.SEVERE, null, ex);
        }
        m.reset();
        m.update(message.getBytes());
        byte[] digest = m.digest();
        BigInteger bigInt = new BigInteger(1, digest);
        String hashtext = bigInt.toString(16);
// Now we need to zero pad it if you actually want the full 32 chars.
        while (hashtext.length() < 32) {
            hashtext = "0" + hashtext;
        }
        return hashtext;

    }
}
